﻿@{
    Layout = "~/_SiteLayout.cshtml";
    Page.Title = "BioBooking";

    // Connecting to webservices
    RemoteService.WebRemoteServiceClient _remoteService = new RemoteService.WebRemoteServiceClient();

    // Get Cinemas
    List<RemoteService.Cinema> _cinemas = _remoteService.GetCinemas();
    List<RemoteService.Movie> _movies = new List<RemoteService.Movie>();
    
    // Check if cookies with bio info exists
    if (Request.Cookies["bioId"] != null && Request.Cookies["bioName"] != null)
    {   
        // Get current cinema
        RemoteService.Cinema cinema = _cinemas.Where(c => c.Id == Convert.ToInt32(Request.Cookies["bioId"].Value)).Single();
        
        // Get movies in cinema
        _movies = _remoteService.GetMoviesUsingCinema(cinema);
    }
    
}

@section featured {
<section class="featured">
    <div class="content-wrapper">
        <hgroup class="title">
            <h2>Welcome to 
            <!-- If bio is selected, write the name -->
            @if (Request.Cookies["bioId"] != null && Request.Cookies["bioName"] != null)
            {
                @Request.Cookies["bioName"].Value.ToString();
            }
            </h2>
<p>
    Vivamus et augue ante, sed congue nunc. Integer condimentum, ligula ac cursus placerat, erat urna sagittis nulla, eu rhoncus leo velit sed risus. Etiam vitae mauris lacus, at venenatis lorem. Pellentesque egestas laoreet magna nec ultrices. Maecenas tempor enim at felis faucibus iaculis et ac dolor. Proin pharetra lacinia egestas.
</p>
        </hgroup>
    </div>
</section>
}


<h2>Currently playing movies</h2>
<ol class="movieList">
    @{
        // Print movie posters and create hyperlinks
        foreach (RemoteService.Movie m in _movies) {
            if (m.ImgUrl != "") 
            {
                <li><a href="~/Movie?id=@m.Id"><img class="movieImg" src="@m.ImgUrl" /></a></li>
            } else 
            {
                <li><a href="~/Movie?id=@m.Id"><img class="movieImg" src="images/question%20mark.jpg" /></a></li>
            }
        }
    }
</ol>